﻿#pragma once
#include <QObject>
#include <QFileInfo>
#include <QDir>
#include <QDebug>
#include <QMap>
#include <QPair>
#include <QByteArray>
#include <boost/crc.hpp>

enum XCompareType
{
	XFile_UnKnown = 0,
	XFile_Equal,
	XFile_Difference,
	XFile_NoExist,
};
using CrcType = QPair<QFileInfo, qulonglong>;
using FileInfoCrcList = QList<CrcType>;
using CheckType = QPair<QFileInfo, XCompareType>;
using FileInfoCheckList = QList<CheckType>;

Q_DECLARE_METATYPE(XCompareType)
Q_DECLARE_METATYPE(CrcType)
Q_DECLARE_METATYPE(FileInfoCrcList)
Q_DECLARE_METATYPE(CheckType)
Q_DECLARE_METATYPE(FileInfoCheckList)

class XCompareDir : public QObject
{
	Q_OBJECT

public:

public:
	XCompareDir(QString left = "", QString right = "")
		:m_strLeft(left), m_strRight(right)
	{
	}

	~XCompareDir()
	{

	}

	static void show(QVariantMap list)
	{
		qDebug() << "++++++++++++++++++";
		for (auto iter = list.begin(); iter != list.end(); iter++)
		{
			qDebug() << iter.key() << "    " << iter.value();
		}
		qDebug() << "++++++++++++++++++";
		//for (auto info : list)
		//{
		//	qDebug() << info.key() << "    " << ((info.second == File_NoExist) ? "no File_NoExist" : (info.second == File_Equal) ? "File_Equal" : "File_Difference");
		//}
	}

	void Work();
	QVariantList Compare();
	//bool IsNull();

private:

	// now is current compare, the result is now compare tmp;
	//FileInfoCheckList GetCheckList(FileInfoCrcList leftList, FileInfoCrcList rightList);
	QVariant GetCheckList(FileInfoCrcList leftList, FileInfoCrcList rightList);
	FileInfoCrcList GetCrcList(QFileInfoList & infoList);
	bool GetDirCrc(QFileInfo info, qulonglong & crc);
	bool GetCrc(QFileInfo & info, qulonglong & crc);

	bool EqualFileName(const QFileInfo & left, const QFileInfo & right)
	{
		return left.fileName().compare(right.fileName(), Qt::CaseInsensitive);
	}
public:
	QString m_strLeft;
	QString m_strRight;
};



//Q_DECLARE_METATYPE(XCompareDir::FileInfoCheckList);
